package com.hfi.security.app.authentication;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;

/**
 * @author ChangLiang
 * @date 2019/9/8
 */
public class HfiOAuthExceptionSerializer extends StdSerializer<HfiOAuthException> {

    public HfiOAuthExceptionSerializer() {
        super(HfiOAuthException.class);
    }

    @Override
    public void serialize(HfiOAuthException e, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeStartObject();
        jsonGenerator.writeStringField("errorcode", String.valueOf(e.getHttpErrorCode()));
        jsonGenerator.writeStringField("value", e.getMessage());
        jsonGenerator.writeEndObject();
    }
}
